package com.jymj.service.impl;

import com.jymj.dao.ZhaiDao;
import com.jymj.entity.KeyValueEntity;
import com.jymj.entity.huji.ZhaiEntity;
import com.jymj.service.ZhaiService;
import com.jymj.utils.RRException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ljj on 2017/4/6.
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class zhaiServiceImpl implements ZhaiService {

    @Resource
    private ZhaiDao zhaiDao;

    @Override
    public List<ZhaiEntity> getZhaiEntity(Integer objectid,Integer household) {
        return zhaiDao.getZhaiEntity(objectid,household);
    }

    @Override
    public List<ZhaiEntity> getZhaiByCunName(String cunName) {
        return zhaiDao.getZhaiByCunName(cunName);
    }

    //1
    @Override
    public Map getHuQuery(Integer pageSize, Integer currPage, ZhaiEntity zhai, List code) {
        Map map = new HashMap();
        List<ZhaiEntity> zhaiList;
        Map map1 = new HashMap();
        if (pageSize != null && currPage != null) {
            map1.put("pageSize", pageSize);
            map1.put("currPage", currPage);
            map1.put("zhai", zhai);
            map1.put("code", code);
            zhaiList = zhaiDao.getHuQuery(map1);
        } else {
            map1.put("zhai", zhai);
            map1.put("code", code);
            zhaiList = zhaiDao.getHuExcelQuery(map1);
        }
        zhaiList.removeAll(Collections.singleton(null));
        map.put("zhaiList", zhaiList);
        int allCount = zhaiDao.getHuQueryCount(map1);
        map.put("allCount", allCount);
        return map;
    }

    //1
    @Override
    public List<KeyValueEntity> queryByAge(ZhaiEntity zhai, List code) {
        Map map = new HashMap();
        map.put("zhai", zhai);
        map.put("code", code);
        return zhaiDao.queryByAge(map);
    }

    //1
    @Override
    public List<KeyValueEntity> queryBysex(ZhaiEntity zhai, List code) {
        Map map = new HashMap();
        map.put("zhai", zhai);
        map.put("code", code);
        return zhaiDao.queryBysex(map);
    }

    //1
    @Override
    public List<KeyValueEntity> queryByEmp(ZhaiEntity zhai, List code) {
        Map map = new HashMap();
        map.put("zhai", zhai);
        map.put("code", code);
        return zhaiDao.queryByEmp(map);
    }

    //1
    @Override
    public List<KeyValueEntity> queryByHuType(ZhaiEntity zhai, List code) {
        Map map = new HashMap();
        map.put("zhai", zhai);
        map.put("code", code);
        return zhaiDao.queryByHuType(map);
    }

    //1
    @Override
    public List<KeyValueEntity> getse0ByFrame(String points, String code) {
        Map map = new HashMap();
        map.put("points", points);
        map.put("code", code);
        return zhaiDao.getse0ByFrame(map);
    }

    //1
    @Override
    public List<KeyValueEntity> getse1ByFrame(String points, String code) {
        Map map = new HashMap();
        map.put("points", points);
        map.put("code", code);
        return zhaiDao.getse1ByFrame(map);
    }

    //1
    @Override
    public List<KeyValueEntity> getse2ByFrame(String points, String code) {
        Map map = new HashMap();
        map.put("points", points);
        map.put("code", code);
        return zhaiDao.getse2ByFrame(map);
    }

    //1
    @Override
    public Integer getZhaiListCount(String points, String code) {
        Map map = new HashMap();
        map.put("points", points);
        map.put("code", code);
        return zhaiDao.getZhaiListCount(map);
    }

    @Override
    public List<ZhaiEntity> getHujiByObid(Integer objectid) {
        return zhaiDao.getHujiByObid(objectid);
    }

    @Override
    public List<ZhaiEntity> getZhaiListExcel(Map map) {
        return zhaiDao.getZhaiListExcel(map);
    }

    @Override
    public void update(ZhaiEntity zhaiEntity) {
        zhaiDao.update(zhaiEntity);
    }

    @Override
    public void save(ZhaiEntity zhaiEntity) {
        zhaiDao.save(zhaiEntity);
    }

    @Override
    public ZhaiEntity getzhai(Integer objectid,Integer household) {
        return zhaiDao.getzhai(objectid,household);
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void deleteHuji(Long[] ids) {
        int i = zhaiDao.deleteHuji(ids);
        if (i <= 0){
            throw new RRException("删除失败");
        }
    }

    @Override
    public void updateHu(Integer ylId, Integer household) {
        zhaiDao.updateHu(ylId,household);
    }

    @Override
    public List<ZhaiEntity> getHuji(Integer ylId) {
        return zhaiDao.getHuji(ylId);
    }

    //1
    @Override
    public List<ZhaiEntity> getZhaiList(Map map) {
        return zhaiDao.getZhaiList(map);
    }

    //1
    @Override
    public List<KeyValueEntity> queryByEmp(String points, String code) {
        Map map = new HashMap();
        map.put("points", points);
        map.put("code", code);
        return zhaiDao.getByEmp(map);
    }

    //1
    @Override
    public List<KeyValueEntity> queryByHuType(String points, String code) {
        Map map = new HashMap();
        map.put("points", points);
        map.put("code", code);
        return zhaiDao.getByHuType(map);
    }

}
